﻿Imports System.Data.OleDb

Public Class _like
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        img_like.Visible = False
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("IslandConnectionString").ConnectionString)
        Dim sql = "select * from userlikes where Reader = @f1 and commentID = @f2"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f2", Request.Params("ID"))
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        If dr.HasRows Then
            img_like.Visible = True
            btn_like.Visible = False
        Else
            img_like.Visible = False
            btn_like.Visible = True
        End If
        conn.Close()
        

    End Sub

    Protected Sub btn_like_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_like.Click
        img_like.Visible = True
        btn_like.Visible = False
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("IslandConnectionString").ConnectionString)
        Dim sql = "Insert into userlikes(commentID,Reader) values (@f1,@f2)"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        cmd.Parameters.AddWithValue("@f2", User.Identity.Name)
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
    End Sub
End Class